using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DTO;
using DAO;
namespace BUS
{
    public enum PhieuTraSachBUSResult
    {
        OK, DAOERROR
    }
    public class PhieuTraSach
    {
        public static int PhatSinhMa()
        {
            DAO.PhieuTraSach dao = new DAO.PhieuTraSach();
            string sql = "SELECT TOP 1 MaPhieuTra FROM PhieuTraSach ORDER BY MaPhieuTra DESC";

            DataTable dt = dao.Select(sql);
            if (dt.Rows.Count == 0)
                return 1;
            else
                return (int.Parse(dt.Rows[0][0].ToString()) + 1);
        }
        public static PhieuTraSachBUSResult Them(DTO.PhieuTraSach s)
        {
            DAO.PhieuTraSach dao = new DAO.PhieuTraSach();
            string sql = "INSERT INTO PhieuTraSach VALUES(";
            sql += s.MaPhieuTra + ", ";
            sql += s.MaDocGia + ", ";
            sql += "'" + s.NgayTra + "', ";
            sql += "'" + s.TienPhat + "')";
            if (dao.Insert(sql))
                return PhieuTraSachBUSResult.OK;
            return PhieuTraSachBUSResult.DAOERROR;
        }
    }
}
